home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00011_utilityMethods parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  4.1 KB  |  150 lines

  1. -- 2000.03.12
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- miscellaneous stuff:
  7.  
  8. ------------------------------------------------------------------------------------------------------
  9.  
  10. -- declare properties:
  11. property main       -- main code directory object
  12. property pathDelims -- a #propList of platform-specific pathname delimiter symbols
  13.  
  14. ------------------------------------------------------------------------------------------------------
  15.  
  16. on new me,L
  17.   
  18.   -- (1) extract and check arguments:
  19.   
  20.   -- check for a parameter list:
  21.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"utilityMethods:new"]
  22.   
  23.   -- a reference to the parent codebase is REQUIRED:
  24.   main = L[#main]
  25.   if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"utilityMethods:new"]
  26.   
  27.   --------------------
  28.   
  29.   -- store a #propList of path delimiters:
  30.   pathDelims = [:]
  31.   pc  = "\"
  32.   mac = ":"
  33.   pathDelims[#PC]  = [#lookFor:mac, #replaceWith:pc]
  34.   pathDelims[#Mac] = [#lookFor:pc, #replaceWith:mac]
  35.   
  36.   --------------------
  37.   
  38.   -- pass back my address:
  39.   return me
  40.   
  41.   ----------------------------------------------------------------------------------------------------
  42.   
  43. on listFromText me,t
  44.   
  45.   -- this converts the multiple-line string t into a lingo propList:
  46.   
  47.   -- must have a string!
  48.   if not stringP(t) then return #null
  49.   if not length(t) then return #null
  50.   
  51.   --------------------
  52.   
  53.   -- create an empty container:
  54.   L = [:]
  55.   
  56.   -- recurse over each line:
  57.   repeat with i = 1 to the number of lines of t
  58.     
  59.     x = t.line[i]
  60.     
  61.     -- blank lines are treated as EOF!
  62.     if not length(x) then exit repeat
  63.     
  64.     -- ASSUMPTION: the first word on each line is the property name to be used;
  65.     -- the remainder is the data item to be stored:
  66.     p = x.word[1]   
  67.     delete word 1 of x
  68.     
  69.     -- look out for stringised lists and symbols:
  70.     v = value(x)
  71.     if listP(v) or symbolP(v) then x = v   
  72.     
  73.     -- assign the value to a named location:
  74.     L[symbol(p)] = x
  75.     
  76.   end repeat
  77.   
  78.   -- pass back to the caller:
  79.   return L
  80.   
  81.   ----------------------------------------------------------------------------------------------------
  82.   
  83. on parseFilePath me,p
  84.   
  85.   -- parse the filepath string p supplied so it contains platform specific pathname delimiters:
  86.   
  87.   -- a string is required:
  88.   if not stringP(p) then return ┬¼
  89.   [#error:#noStringSupplied, #msg:"utilityMethods:getPlatFormFilePath"]
  90.   
  91.   if not length(p) then return ┬¼
  92.   [#error:#emptyString, #msg:"utilityMethods:getPlatFormFilePath"]
  93.   
  94.   --------------------
  95.   
  96.   -- process delimiters according to the runtime platform:
  97.   um = main.getUtilityMethods()
  98.   x  = um.thePlatform()
  99.   L  = pathDelims[x]
  100.   
  101.   -- in the path p supplied, we need to replace what character with what other character?
  102.   a = L[#lookFor]
  103.   b = L[#replaceWith]
  104.   
  105.   --------------------
  106.   
  107.   -- begin replacing characters from what position?
  108.   z = 1
  109.   
  110.   -- wrinkle:
  111.   
  112.   -- p might begin with something like "D:\" -- in this case, we need to ensure the colon is
  113.   -- preserved when forcing p to a pc filePath (mac paths use a colon as a delimiter!)
  114.   if (p.char[2] = ":") and (x = #PC) then z = 3
  115.    
  116.   --------------------
  117.    
  118.   -- search and replace:
  119.   repeat with i = z to length(p)
  120.         
  121.     if char i of p <> a then next repeat
  122.     put b into char i of p
  123.     
  124.   end repeat
  125.   
  126.   --------------------
  127.   
  128.   -- pass back processed string to the caller:
  129.   return p
  130.   
  131.   ----------------------------------------------------------------------------------------------------
  132.   
  133. on thePlatform me
  134.   
  135.   -- pass back an identification of the current platform:
  136.   if the platform starts "Win" then return #PC
  137.   else return #Mac
  138.   
  139.   ----------------------------------------------------------------------------------------------------
  140.   
  141. on printStr me,s
  142.   
  143.   -- attempt to show the feedback message string s:
  144.   sm = main.getServiceManager()
  145.   fb = sm.getService(#feedbackService)
  146.   if (ilk(fb) <> #instance) then return fb
  147.   
  148.   fb.feedbackMsg(s)
  149.   
  150.   ----------------------------------------------------------------------------------------------------